home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / Mandlebrot / Mandlebrot Folder / Mandelbrot.c < prev    next >
C/C++ Source or Header  |  1990-05-07  |  5KB  |  183 lines

  1. /* *********************************************************************************
  2.      
  3.       FILE:            Mandelbrot.c
  4.       
  5.      DESCRIPTION:    Translated from Mandel -- Pascal Application in "On MacIntosh 
  6.                      Programming: Advanced Techniques", Daniel K. Allen, 
  7.                      Addison-Wesley, 1989 pp. 88-100
  8.                       
  9.      AUTHOR:        Bruce E. Gladstone
  10.      
  11.      Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  12.      
  13.      Revision History:
  14.      ============================================================
  15.      5/1/90    - Release to Compuserve
  16.      ============================================================
  17.      
  18.      COMMENTS:
  19.      
  20.      None. 
  21.  
  22.    ******************************************************************************** */        
  23.  
  24. #include <stdio.h> 
  25. #include <QuickDraw.h>
  26. #include <MacTypes.h> 
  27. #include <WindowMgr.h>
  28. #include <MenuMgr.h>
  29. #include <EventMgr.h>
  30. #include <DeskMgr.h>
  31. #include <FileMgr.h> 
  32. #include <ToolboxUtil.h> 
  33. #include <ControlMgr.h>
  34. #include <color.h>
  35. #include <colortoolbox.h>
  36. #include "Mandelbrot.h"
  37.  
  38. /* ---------------------------- Global Variables ---------------------------------- */
  39.  
  40. int                colorQD;
  41. int                quitFlag;
  42. int                linearFlag;
  43. int                custPict;
  44. int                numColorBits;
  45. int                numColors, brushSize;
  46. int                limit;
  47. int                n;
  48. long            startTime, now;
  49. float            res;
  50. float            centx, centy;
  51. float            xmin, xmax, ymin, ymax;
  52. float            delx, dely;
  53.  
  54. /* ---------------------------- Global MacTypes ----------------------------------- */
  55.  
  56. Str255            str;
  57. CTabHandle        myColorHandle;
  58. RGBColor        aColor;
  59. Rect            myRect, dragRect;
  60. WindowPtr        aboutWindow;        
  61. MenuHandle        appleMenu, mandelMenu, editMenu, xMenu, yMenu, resMenu, timeMenu;
  62. WindowPtr        myWindow;
  63.  
  64. /* ---------------------------  Local Prototypes  --------------------------------- */
  65.  
  66. int main ( void );
  67. void initWorld ( void );
  68. void drawMandel ( void );
  69. void menuBarInit ( void );
  70. void windowInit ( void );
  71.  
  72. /* --------------------------------------------------------------------------------
  73.     main - 5/01/90 beg
  74.    -------------------------------------------------------------------------------- */
  75. int
  76. main() 
  77. {
  78.     initWorld ();
  79.     while  ( !quitFlag )
  80.     {    
  81.         startTime = TickCount();
  82.         drawMandel ();    
  83.     }
  84.     DisposeWindow ( myWindow );
  85.     return (0);            /*    Back to shell    */
  86. }  /* main  */
  87.  
  88. /* --------------------------------------------------------------------------------
  89.     initWorld - 5/01/90 beg
  90.     Initialization code: makes the window, builds the menus, sets the colors
  91.     sets up the default Mandelbrot parms
  92.    -------------------------------------------------------------------------------- */
  93. void
  94. initWorld ()
  95. {
  96.     MaxApplZone ();
  97.     InitGraf ( &thePort );
  98.     InitFonts ();
  99.     InitWindows ();
  100.     InitMenus ();
  101.     TEInit ();
  102.     InitDialogs ( nil );
  103.     InitCursor();
  104.     menuBarInit();
  105.     windowInit();
  106.     FlushEvents ( everyEvent,0 );
  107.     
  108.     /*   Mandel defaults   */
  109.     
  110.     centx = -0.8;
  111.     centy =  0.0;
  112.     res   =  1.0;
  113.     limit =  256;
  114.     linearFlag = FALSE;
  115.     custPict = 1;
  116.     quitFlag = FALSE;
  117.     brushSize = 8;
  118.     
  119. } /*  initWorld ()  */
  120.  
  121. /* --------------------------------------------------------------------------------
  122.     menuBarInit - 5/01/90 beg
  123.    -------------------------------------------------------------------------------- */
  124.  
  125. void
  126. menuBarInit()
  127. {
  128.     Handle    mandelMenuBar;
  129.         
  130.     mandelMenuBar = GetNewMBar ( appleID );
  131.     SetMenuBar ( mandelMenuBar );
  132.     appleMenu = GetMHandle ( appleID );
  133.     AddResMenu ( appleMenu, 'DRVR' );    
  134.     mandelMenu = GetMHandle ( mandelID );
  135.     editMenu = GetMHandle ( editID );
  136.     CheckItem ( mandelMenu, 2, TRUE );
  137.     CheckItem ( mandelMenu, 5, TRUE );
  138.     CheckItem ( mandelMenu, 11, TRUE );
  139.     DrawMenuBar();
  140.     
  141. } /* menuBarInit() */
  142.  
  143. /* --------------------------------------------------------------------------------
  144.     windowInit - 5/01/90 beg
  145.    -------------------------------------------------------------------------------- */
  146.  
  147. void
  148. windowInit()
  149. {
  150.     long    cflag;
  151.     cflag = ROM85;
  152.         
  153.     SetRect ( &dragRect, -32768, -32768, 32767, 32767 );
  154.     myRect = screenBits.bounds;
  155.     myRect.top += 45;
  156.     myRect.left += 10;
  157.     myRect.right -= 10;
  158.     myRect.bottom -= 10;
  159.  
  160.     colorQD = (*((int*)cflag) & 0xC000) == 0;    
  161.     if  ( colorQD )
  162.     {
  163.         myWindow = NewCWindow(nil, &myRect, "\pMandel", TRUE, zoomDocProc,
  164.             (CWindowPtr)-1, TRUE, 0);
  165.         numColorBits = (**(*(CGrafPtr)myWindow).portPixMap).pixelSize;
  166.         numColors = 1 << numColorBits;
  167.         myColorHandle = GetCTable ( numColorBits );    /* Should get default clut */
  168.     }
  169.      else
  170.     {
  171.          myWindow = NewWindow(nil, &myRect, "\pMandel", TRUE, zoomDocProc,
  172.             (CWindowPtr)-1, TRUE, 0);
  173.     }
  174.         
  175.     SetPort ( myWindow );
  176. }  /* windowInit() */
  177.  
  178. /* ===============================  EOF  ==========================================
  179.     Copyright © 1990 by Bruce E. Gladstone, All Rights Reserved.
  180.    ================================================================================ */
  181.  
  182.  
  183.